package com.example.message_wall_spring.service;

import com.example.message_wall_spring.mapper.MessageInfoMapper;
import com.example.message_wall_spring.model.MessageInfo;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.StringUtils;
import org.springframework.stereotype.Service;

import java.util.List;

@Slf4j
@Service
public class MessageInfoService {
    @Autowired
    private MessageInfoMapper messageInfoMapper;
    public boolean publish(MessageInfo messageInfo) {
        if (!StringUtils.hasLength(messageInfo.getFrom()) || !StringUtils.hasLength(messageInfo.getTo()) ||
                !StringUtils.hasLength(messageInfo.getSay())) {
            log.error("输入的留言信息存在空信息");
            return false;
        }else {
            messageInfoMapper.add(messageInfo);
            return true;
        }
    }


    public List<MessageInfo> getMessage() {
        return messageInfoMapper.getAll();
    }
}
